﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace landlord2lib
{
    public class CardGroupSingle : CardGroup
    {
        public CardGroupSingle(Card[] cards)
        {
            m_cards = cards;
        }

        public override bool IsValid()
        {
            try
            {
                if (m_cards.Length != CardCount) return false;
                foreach (Card card in m_cards) card.Reset();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public override int CompareTo(CardGroup other)
        {
            try
            {
                if (other is CardGroupSingle)
                {
                    CardGroupSingle o = (CardGroupSingle)other;
                    return m_cards[0].CompareTo(o.m_cards[0]);
                }
                else return -1;
            }
            catch
            {
                return 0;
            }
        }

        public static int CardCount
        {
            get
            {
                return 1;
            }
        }

        public static HintCardCollection Hint(Card[] handCards, CardGroupSingle lastGroup)
        {
            HintCardCollection result = new HintCardCollection();
            try
            {
                CardStack stack = new CardStack(handCards);
                CardPoint minPt = lastGroup.Cards[0].ComparePoint;
                for (int pt = (int)minPt + 1; pt <= (int)CardPoint.CardJoker; pt++)
                {
                    if ((pt == (int)CardPoint.Card2 && stack[pt].Count >= 1) || stack[pt].Count == 1) result.AddHint(new Card[] { stack[pt][0] });
                }
                return result;
            }
            catch
            {
                return result;
            }
        }
    }
}
